import 'package:flutter/material.dart';

// ignore: must_be_immutable
class EditDialog extends Dialog {
  String text;
  String title;
  final TextEditingController _controller = new TextEditingController();

  EditDialog({Key key, this.title = "标题", this.text}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var margin = MediaQuery.of(context).size.height / 4;
    return new Material(
      //创建透明层
      type: MaterialType.transparency, //透明类型
      child: Container(
        child: Stack(
          alignment: Alignment.topCenter,
          children: <Widget>[
            Container(
              height: 90,
              width: 320,
              margin: EdgeInsets.only(top: margin),
              decoration: ShapeDecoration(
                color: Color(0xffffffff),
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.all(
                    Radius.circular(8.0),
                  ),
                ),
              ),
              child: Column(
                children: <Widget>[
                  Container(
                    height: 30,
                    child: Stack(
                      fit: StackFit.loose,
                      overflow: Overflow.clip,
                      textDirection: TextDirection.ltr,
                      alignment: Alignment.center,
                      children: <Widget>[
                        Container(
                          padding: EdgeInsets.only(top: 30),
                          child: Divider(
                            height: 1.5,
                          ),
                        ),
                        Positioned(
                          right: 0,
                          child: IconButton(
                            icon: Icon(Icons.close),
                            onPressed: () {
                              Navigator.pop(context);
                            },
                          ),
                        ),
                      ],
                    ),
                  ),
                  Container(
                    width: 320.0,
                    height: 50.0,
                    padding: EdgeInsets.all(8),
                    child: new Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: <Widget>[
                        Container(
                          padding: EdgeInsets.only(top: 10),
                          child: Text(title),
                        ),
                        Expanded(
                          child: new Container(
                            padding: EdgeInsets.only(left: 10, right: 10),
                            child: TextField(
                              autofocus: true,
                              decoration: const InputDecoration(
                                contentPadding:
                                    const EdgeInsets.symmetric(vertical: 6),
                              ),
                              controller: _controller,
                            ),
                          ),
                        ),
                        Container(
                          child: FlatButton(
                            onPressed: () {
                              Navigator.of(context).pop(_controller.text);
                            },
                            child: Text("确定"),
                            color: Colors.blue,
                            textColor: Colors.white,
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
